﻿Imports System.Data.OleDb

Public Class Register
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)

        Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
        If String.IsNullOrEmpty(continueUrl) Then
            continueUrl = "~/"
        End If

        Dim sql As String = "INSERT INTO UserProfile (dinerID, dateOfRegister) VALUES (@f1,@f2)"        'This is an SQL statment
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("SpiritConnString").ConnectionString)       'Connect to the Database
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)

        conn.Open()
        cmd.Parameters.AddWithValue("@f1", RegisterUser.UserName)       'The 'RegisterUser.UserName' is the same with User.Identity.Name
        cmd.Parameters.AddWithValue("@f2", Format(Now(), "yyyy-MM-dd ") & Format(Now(), "HH:mm:ss"))
        'I do not use the 'DateTime.Now.Date()', because my Access is Chinese version, but my system is English. The time formate is different
        cmd.ExecuteNonQuery()

        conn.Close()

        Response.Redirect("~/EditProfile.aspx")
    End Sub
End Class